﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Collections;
using TestMySqlConnetPoll;
using System.Threading;
using View.Common;

namespace View.History
{
    public partial class FrmUserConFrimAlarm : DevExpress.XtraEditors.XtraForm
    {
        public ArrayList list = new ArrayList();
        public FrmUserConFrimAlarm()
        {
            InitializeComponent();
            LoadUserList();
        }

        private void BtnOK_Click(object sender, EventArgs e)
        {
            AlarmTable alarmTable = new AlarmTable();
            List<ObjAlaram> objList = new List<ObjAlaram>();

            foreach (HistroyAlarmObj obj in list)
            {
                ObjAlaram alarm = new ObjAlaram();                
                alarm = obj.alarmObj;
                alarm.ConfirmName = this.comboBox_user.SelectedItem as string;
                alarm.ConfirmText = txtConfrim.Text;
                alarm.ConfirmTime = MySql.DateTimeToTime_t(DateTime.Now);
                objList.Add(alarm);
            }

            alarmTable.InsertData_AlarmTable(objList);

            rtAlarmTable arb = new rtAlarmTable();
            arb.Delete(objList);    //删除实时显示表
            UtilityFunc.DelSourceLevel(objList);
            
            this.Close();
        }

        private void LoadUserList()
        {
            UserTable user = new UserTable();
            user.ReadUserList();
            while (!user.ReadyUserList)
            {
                if (user.ErrorFlag != 0)
                {
                    return;
                }

                Thread.Sleep(20);
            }

            foreach (objUser obj in user.UserList)
            {
                this.comboBox_user.Items.Add(obj.Name);
            }

            this.comboBox_user.SelectedIndex = 0;

        }

        private void BtnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}